home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / options.el.z / options.el
Encoding:
Text File  |  1998-05-21  |  4.9 KB  |  148 lines

  1. ;;; options.el --- edit Options command for XEmacs.
  2.  
  3. ;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  22. ;; 02111-1307, USA.
  23.  
  24. ;;; Synched up with: FSF 19.34.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; This code provides functions to list and edit the values of all global
  29. ;; option variables known to loaded Emacs Lisp code.  There are two entry
  30. ;; points, `list-options' and `edit-options'.  The latter enters a major
  31. ;; mode specifically for editing option values.  Do `M-x describe-mode' in
  32. ;; that context for more details.
  33.  
  34. ;;; Code:
  35.  
  36. ;;;###autoload
  37. (defun list-options ()
  38.   "Display a list of XEmacs user options, with values and documentation."
  39.   (interactive)
  40.   (save-excursion
  41.     (set-buffer (get-buffer-create "*List Options*"))
  42.     (Edit-options-mode))
  43.   (with-output-to-temp-buffer "*List Options*"
  44.     (let (vars)
  45.       (mapatoms #'(lambda (sym) ; XEmacs
  46.             (and (boundp sym)
  47.              (user-variable-p sym)
  48.              (not (specifierp (symbol-value sym)))
  49.              (not (glyphp (symbol-value sym)))
  50.              (setq vars (cons sym vars)))))
  51.       (setq vars (sort vars 'string-lessp))
  52.       (while vars
  53.     (let ((sym (car vars)))
  54.       (princ ";; ")
  55.       (prin1 sym)
  56.       (princ ":\n\t")
  57.       (prin1 (symbol-value sym))
  58.       (terpri)
  59.       (princ (substitute-command-keys 
  60.           (documentation-property sym 'variable-documentation)))
  61.       (princ "\n;;\n"))
  62.     (setq vars (cdr vars)))))
  63.   (save-excursion
  64.     (set-buffer "*List Options*")
  65.     (setq buffer-read-only t)))
  66.  
  67. ;;;###autoload
  68. (defun edit-options ()
  69.   "Edit a list of XEmacs user option values.
  70. Selects a buffer containing such a list,
  71. in which there are commands to set the option values.
  72. Type \\[describe-mode] in that buffer for a list of commands."
  73.   (interactive)
  74.   (list-options)
  75.   (pop-to-buffer "*List Options*"))
  76.  
  77. (defvar Edit-options-mode-map
  78.   (let ((map (make-keymap)))
  79.     (define-key map "s" 'Edit-options-set)
  80.     (define-key map "x" 'Edit-options-toggle)
  81.     (define-key map "1" 'Edit-options-t)
  82.     (define-key map "0" 'Edit-options-nil)
  83.     (define-key map "p" 'backward-paragraph)
  84.     (define-key map " " 'forward-paragraph)
  85.     (define-key map "n" 'forward-paragraph)
  86.     map)
  87.   "")
  88.  
  89. ;; Edit Options mode is suitable only for specially formatted data.
  90. (put 'Edit-options-mode 'mode-class 'special)
  91.  
  92. (defun Edit-options-mode ()
  93.   "\\<Edit-options-mode-map>\
  94. Major mode for editing XEmacs user option settings.
  95. Special commands are:
  96. \\[Edit-options-set] -- set variable point points at.  New value read using minibuffer.
  97. \\[Edit-options-toggle] -- toggle variable, t -> nil, nil -> t.
  98. \\[Edit-options-t] -- set variable to t.
  99. \\[Edit-options-nil] -- set variable to nil.
  100. Changed values made by these commands take effect immediately.
  101.  
  102. Each variable description is a paragraph.
  103. For convenience, the characters \\[backward-paragraph] and \\[forward-paragraph] move back and forward by paragraphs."
  104.   (kill-all-local-variables)
  105.   (set-syntax-table emacs-lisp-mode-syntax-table)
  106.   (use-local-map Edit-options-mode-map)
  107.   (make-local-variable 'paragraph-separate)
  108.   (setq paragraph-separate "[^\^@-\^?]")
  109.   (make-local-variable 'paragraph-start)
  110.   (setq paragraph-start "\t")
  111.   (setq truncate-lines t)
  112.   (setq major-mode 'Edit-options-mode)
  113.   (setq mode-name (gettext "Options")) ; XEmacs
  114.   (run-hooks 'Edit-options-mode-hook))
  115.  
  116. (defun Edit-options-set () (interactive)
  117.   (Edit-options-modify
  118.    '(lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": ")))))
  119.  
  120. (defun Edit-options-toggle () (interactive)
  121.   (Edit-options-modify '(lambda (var) (not (symbol-value var)))))
  122.  
  123. (defun Edit-options-t () (interactive)
  124.   (Edit-options-modify '(lambda (var) t)))
  125.  
  126. (defun Edit-options-nil () (interactive)
  127.   (Edit-options-modify '(lambda (var) nil)))
  128.  
  129. (defun Edit-options-modify (modfun)
  130.   (save-excursion
  131.    (let ((buffer-read-only nil) var pos)
  132.      (re-search-backward "^;; \\|\\`")
  133.      (forward-char 3)
  134.      (setq pos (point))
  135.      (save-restriction
  136.        (narrow-to-region pos (progn (end-of-line) (1- (point))))
  137.        (goto-char pos)
  138.        (setq var (read (current-buffer))))
  139.      (goto-char pos)
  140.      (forward-line 1)
  141.      (forward-char 1)
  142.      (save-excursion
  143.        (set var (funcall modfun var)))
  144.      (kill-sexp 1)
  145.      (prin1 (symbol-value var) (current-buffer)))))
  146.  
  147. ;;; options.el ends here
  148.